<template>
	<view class="container">
		
		<FHeader></FHeader>

		
	</view>
</template>

<script>
import FHeader from './FHeader/index.vue'
export default {
	components:{
			FHeader
		},
	data() {
		return {
		};
	},

	onLoad() {
		// 初始化本地存储
		this.initStorage();

		// 创建动画实例
		this.animation = uni.createAnimation({
			duration: 1000,
			timingFunction: 'ease-in-out'
		});
	},

	computed: {
	},

	methods: {
		// 初始化本地存储
		initStorage() {
			const collection = uni.getStorageSync('fishingCollection');
			const fishCount = uni.getStorageSync('fishingCount');

			if (collection) {
				this.collection = JSON.parse(collection);
			}

			if (fishCount) {
				this.fishCount = parseInt(fishCount);
			}
		},

		// 保存数据到本地存储
		saveStorage() {
			uni.setStorageSync('fishingCollection', JSON.stringify(this.collection));
			uni.setStorageSync('fishingCount', this.fishCount.toString());
		},

		// 显示消息提示
		showMessage(message) {
			uni.showToast({
				title: message,
				icon: 'none'
			});
		},

		// 钓鱼逻辑
		async onFish() {
			if (this.isFishing) return;

			this.isFishing = true;
			this.fishCount++;
			this.saveStorage();

			// 播放钓鱼动画
			// await this.playFishingAnimation();

			// 随机生成钓鱼结果
			const rate = Math.random();
			let cumulativeRate = 0;
			let caughtFish = null;

			// 根据概率确定钓到的鱼
			for (const fish of this.fishTypes) {
				cumulativeRate += fish.rate;
				if (rate <= cumulativeRate) {
					caughtFish = fish;
					break;
				}
			}

			// 处理钓鱼结果
			this.currentFish = caughtFish;

			if (caughtFish) {
				// 检查是否已收集
				const isNew = !this.collection.includes(caughtFish.id);

				if (isNew) {
					this.collection.push(caughtFish.id);
					this.saveStorage();
					this.resultText = `恭喜！钓到了新的${caughtFish.name}！`;
					uni.vibrateLong();
				} else {
					this.resultText = `钓到了${caughtFish.name}！`;
					uni.vibrateShort();
				}
			} else {
				this.resultText = '哎呀，钓了个寂寞！';
				uni.vibrateShort();
			}

			// 显示结果弹窗
			this.showResult = true;
			this.isFishing = false;
		},
	}
};
</script>

<style scoped>
</style>
